package com.pingancar.creditmanage.rest;

import com.pingancar.creditmanage.pojo.OrderitemPojo;
import com.pingancar.creditmanage.pojo.UserPojo;
import com.pingancar.creditmanage.rest.model.BaseResult;
import com.pingancar.creditmanage.service.QueryService;
import com.pingancar.creditmanage.service.UserOrderService;
import com.pingancar.creditmanage.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by SilverStone-WW on 2015/2/12.
 */
@RestController
@RequestMapping(value="/rest/user/")
public class UserController {
    @Autowired
    QueryService queryService;
    @Autowired
    UserOrderService userOrderService;
    @Autowired
    UserServiceImpl userService;

    @RequestMapping("shoplist")
    public BaseResult getShoplist(Integer type, Integer offset) {
        BaseResult baseResult = new BaseResult();
        baseResult.setStatus(-1);
        if (type == null || offset == null)
            return baseResult;
        List l = queryService.getShopinfoList(type, offset, 10, "");
        baseResult.setStatus(0);
        baseResult.setData(l);
        return baseResult;
    }

    @RequestMapping("orderlist")
    public BaseResult getOrderlist(HttpSession session, Integer offset, Integer length, Integer type) {
        BaseResult baseResult = new BaseResult();
        baseResult.setStatus(-1);

        UserPojo userPojo = (UserPojo)session.getAttribute("user");
        if (offset == null || length == null)
            return baseResult;

        List l = userOrderService.getOrderlistByUser(userPojo, offset, length, type);
        baseResult.setData(l);
        baseResult.setStatus(0);
        return baseResult;
    }
}
